package cn.blossoming.service.base.consts;

import cn.blossoming.service.dto.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionConst {
    public static final String SESSION_USER = "session:user";


    private static HttpServletRequest request() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public static HttpSession session() {
        return request().getSession(false);
    }

    public static User getCurrentUser(){
        return (User) session().getAttribute(SESSION_USER);
    }
    public static Integer getCurrentUserId(){
        return getCurrentUser().getId();
    }
}
